<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------


// return [
//     '__pattern__' => [
//         'name' => '\w+',
//     ],
//     '[hello]'     => [
//         ':id'   => ['index/hello', ['method' => 'get'], ['id' => '\d+']],
//         ':name' => ['index/hello', ['method' => 'post']],
//     ],

// ];



       use think\Request;
       $request = Request::instance();
       $path = $request->path();

       //获取入口文件名
       $base_file = $request->baseFile();

       //通过入口文件名 获取当前模块名
       $modular=basename($base_file,'.php');
       //获取请求方式 get/post
       $method = strtolower($request->method(true));
       //$method='post';
       //var_dump($modular,$base_file);
       //获取请求路径的一级目录名，将其作为规则，表示任何非静态规则请求都会匹配到该路由规则
       $path_arr=explode('/',$path);

      //静态规则 判断
       $first_path=$path_arr[0]?'/'.$path_arr[0]:'/';
       $static_rule=is_file(CONF_PATH.$modular.'/route.php')? include CONF_PATH.$modular.'/route.php':array() ;
       if(!empty($static_rule) && !empty($static_rule[$first_path]))
       {
             // dump($first_path,$static_path);
              return [$first_path=>$static_rule[$first_path]];
       }
       return [
           $path_arr[0]. '/:action' =>
              [
                  $path_arr[0] . '/' .$method. ':action',['modular'=>$modular],
              ]


       ];


       // ========后台路由
       // 首页路由
       //Route::get('/','admin/admin/index');
       //Route::get('/menu','admin/admin/menu');
       //Route::get('/header','admin/admin/header');
       //Route::get('/content','admin/admin/content');
       //
       //// 登录路由
       //Route::controller('/login','admin/Login');
       //
       //
       //// 商品模块
       //Route::controller('/goods','admin/Goods');
       //
       //// 订单模块
       //Route::controller('/order','admin/Order');
       //
       //// 用户模块
       //Route::controller('/user','admin/User');
       //// 后台管理员模块
       //Route::controller('/admin','admin/Admin');
       //
       //// 公告模块
       //Route::controller('/announce','admin/Announce');
       //
       //

       // ========接口路由
       // Route::get('/','api/Login/login');

       // Route::controller('/login','api/login');

